package gold.digger;

/**
 * Created by fanzhenyu02 on 2020/6/27.
 * common problem solver template.
 */
public class LC165 {
    public long startExecuteTime = System.currentTimeMillis();


    class Solution {
        public int compareVersion(String version1, String version2) {
            String[] vList1 = version1.split("\\.");
            String[] vList2 = version2.split("\\.");

            int swapFlag = 1;
            if (vList1.length < vList2.length) {
                String[] temp = vList2;
                vList2 = vList1;
                vList1 = temp;
                swapFlag = -1;
            }

            for (int i = 0; i < vList1.length; i++) {
                if (i >= vList2.length) {
                    int countLeft = 0;
                    for (int j = i; j < vList1.length; j++) {
                        countLeft += Integer.valueOf(vList1[j]);
                    }
                    return (countLeft == 0 ? 0 : 1) * swapFlag;
                }
                int vi1 = Integer.valueOf(vList1[i]);
                int vi2 = Integer.valueOf(vList2[i]);
                if (vi1 != vi2) return (vi1 > vi2 ? 1 : -1) * swapFlag;
            }

            return (vList1.length < vList2.length ? -1 : 0) * swapFlag;
        }
    }

    public void run() {
        Solution solution = new Solution();
        System.out.println(solution.compareVersion("1.0", "1.0.0"));
    }

    public static void main(String[] args) throws Exception {
        LC165 an = new LC165();
        an.run();

        System.out.println("\ncurrent solution total execute time: " + (System.currentTimeMillis() - an.startExecuteTime) + " ms.");
    }
}
